<?php
header("Content-type: text/html; charset=utf-8");
include "/var/www/html/new/d/module/qkxproject/api/des/des.class.php";

$data =$_REQUEST[arg];
$ret_array= simplexml_load_string($data);
$body =$ret_array->Body;
//$body = 'uhfmeQlAZR33oajHrb7t3Tn7W2k/ttl8T2yTDO3b4M8vinWEv1f8ejGNh1PE0GZtwXb15VkC7vJSE5UrM1AERS2c0vCmv7xeJc76C942Yhhl/DhjYBpyW3iUQgEGOXBj2ff4ZY7geQzgv1xcndPhD7tTGo9QBSkBjn9GAmnVq1frUIFC0rKV4rwvgTC7UzIzOcu85JhT9bOCR5AW/xKHzCvkHr0rF03VNED4B3wIlfE+eNm5bnor/J6u94vIrb+McCsAo3s7XjhwQKkVCX+4Sj0bG2gZ3348uEafTHGCfYy8BOZdSrSEVzz0w033WPf7ELD3U98AL2zWV4PoDtwi8UgZ1Y4yXkbN7GRXg3Xfgp2VvI8CfZ0Smtj51GKdETv9goTc0fX11ylYJvDpmP1QuR/WTc8YclG0knDOCH+k01Aa8srTyrNH8TNcEwVkJG517pvsB/9Uk5i358vXPw9GNKg7Iah1qgzSL5zh3b6k4T2SO35zOSzLS/l54KDSdUY971kW9vUyCzcaPB1kmD3t6afG5CBx4jpHpLoaTKZbpo5I4pDLQL9zrkt3LEzdKwpFMJ2ko/CJeafCDXmGAWIXXvfLnZVHVTD8F8/HeLiuOuzqyao7WxUxS35B1R13dG7h2K0Rjv0X5eDqyao7WxUxS7BsHPBPcc87Nm7tpKB7HEEMO4YZWPRFGY5ox5j5heOCzrLltXDOoXFRN6kYoODAy0CZEhXMnvM5YpUMX8x7Q4VSmELrjG0bf+F4w9wcGAzmNqpkBzq2mf+1w4KwehhJUMzkDjoU6C1iz7s+TC/aKIjLvvOFQsp4tg==';
logfile(date('Y-m-d H:i:s')."---".$body);

$ac = '16ucom';
$pw = 'c33367701511b4f6020ec61ded352059';
$inSide = new SoapClient(null, array("location" => "http://localhost/open/openService/pft_insideMX.php", "uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

if (!class_exists("go_sql")) {
    include("/var/www/html/new/conf/le.je");
    $le = new go_sql();
    $le->connect();
}
$time= time();
$_pid = '13780366666';
$authcode ='f845cc151cd7bc2ab1635f7f';



$a= new Crypt3Des($authcode);//3des解码
$des = $a->decrypt($body);

$respone_orderid_xml =  simplexml_load_string($des);


$pftorder = (string)$respone_orderid_xml->PartnerOrderId;//票付通订单号
$pftorder_checknum= (string)$respone_orderid_xml->CheckedNumber;//验票张数
$pftorder_totalnum= (string)$respone_orderid_xml->EticketNum;//电子票总数

$pft_order_list = $inSide->Order_Globle_Search(
    0,0,0,0,"",
    "","","","","",
    "","",$pftorder,"",0,
    "","","",1,0,
    0,1,"","","",
    "","","","","",
    "","","1","",""
);

if(strlen($pft_order_list)>50){
    $pft_order_xml=simplexml_load_string($pft_order_list);
    $UUsalerid  = (string)$pft_order_xml->Rec->UUsalerid;
    $UUlid  = (string)$pft_order_xml->Rec->UUlid;
    $UUcode  = (string)$pft_order_xml->Rec->UUcode;
    $UUtnum =(int)$pft_order_xml->Rec->UUtnum;

    $r = $inSide->Terminal_Check_In($UUsalerid,$UUcode,date('Y-m-d H:i:s'),"");

    if(is_numeric($r)){
        logfile($r);
        $repMsg = Err_Word($r);
        $status = (string)$r;

    }else{
        $status = '100';
        $repMsg = 'success';

    }
}





$request = array(
    "RequestCode"=>$_pid,
    "SequenceId"=>$time,
    "Message"=>$repMsg

);
ksort($request);
$other="";
foreach ($request as $k=>$v){
    $other .= strtolower($k)."=".$v."&";

}
$other = substr($other,0,-1);

$_sig = md5($other.$authcode);
//echo $other;
$response = <<<XML
<?xml version='1.0'?>
<Response>
  <Head>
    <StatusCode>$status</StatusCode>
    <RequestCode>$_pid</RequestCode>
    <SequenceId>$time</SequenceId>
    <Signed>$_sig</Signed>
    <Message>$repMsg</Message>
  </Head>
</Response>
XML;

echo $response;
function logfile($txt)
{
    $fp = fopen("feicd_note.txt", "a");
    flock($fp, LOCK_EX);
    fwrite($fp, $txt . "\n");
    flock($fp, LOCK_UN);
    fclose($fp);
}

function Err_Word($r)
{
    $errCode = array(
        '105' => '找不到订单',
        '121' => '订单状态出错,订单已验证',
        '119' => '订单状态出错,已取消或其他状态',
        '521' => '验证间隔时间未到',
        '133' => '游玩时间未到',
        '134' => '游玩时间已过',
        '118' => '终端服务器无响应',
        '1070' => '订单未支付',
    );
    $eword = $errCode[$r];
    if (!$eword) $eword = '其他错误';
    return $eword;
}


?>